open(WRBUFF,"|gzip >ill_allele_build37.tped.gz") or die "not able to write the file\n";
open(BUFF,"su_ill_allele_build37.tped") or die "not able to write the file su_ill_allele_build37.tped\n";
while(<BUFF>)
{
	chomp($_);
	@array=split(" ",$_);
	$hash{$array[1]}=$array[3];
}
for($i=1;$i<24;$i++)
{
	$chr=$i;
	open(HAPS,"gunzip -c ./kk/$chr/snps_chr$chr.haps.gz |") or die "not able to write the file snps_chr1.haps.gz\n";
	open(WRHAPS,"|gzip > ./kk/$chr/temp_chr$chr.haps.gz") or die "not able to write temp_chr$chr.haps.gz\n";
	while(<HAPS>)
	{
		chomp($_);
		@haps=split(" ",$_);
		if(exists($hash{$haps[1]}))
		{
			$haps[2]=$hash{$haps[1]};
			$_=join(" ",@haps);
			print WRHAPS $_."\n";
			#delete($hash{$haps[1]});
		}
	}
	close(WRHAPS);
	close(HAPS);
	$sys ="gunzip -c ./kk/$chr/temp_chr$chr.haps.gz|sort -k3,3n |gzip > ./kk/$chr/snps_chr$chr.haps.gz";
	system($sys);
	system("rm ./kk/$chr/temp_chr$chr.haps.gz");
	
}
open(BUFF,"gunzip -c fwdStrandResults_input.tped.gz|") or die "not able to write the file su_ill_allele_build37.tped\n";
while(<BUFF>)
{
        chomp($_);
        @array=split(" ",$_);
        if(exists($hash{$array[1]}))
	{
		$array[3]=$hash{$array[1]};
		$_=join(" ",@array);
		print WRBUFF $_."\n";
	}
}

